package Base.InterFaceTest;

/**
 * desc 接口的使用
 * 1. 此列体现了接口的多态性
 * 2. 接口实际上体现了一种规范性
 * 3. 体会面向接口编程
 *
 */
public class USBTest {
    public static void main(String[] args) {
        Computer computer = new Computer();
        // 创建了接口的非匿名实现类的非匿名对象
        Flash flash = new Flash();
        computer.transferData(flash);

        System.out.println("=================");

        // 创建接口非匿名实现类的匿名对象
        computer.transferData(new Flash());

        System.out.println("==================");

        // 创建了接口的匿名实现类的非匿名对象
        final USB phone = new USB() {
            @Override
            public void start() {
                System.out.println("The phone start work!");
            }

            @Override
            public void stop() {
                System.out.println("The phone stop work!");
            }
        };

        computer.transferData(phone);

        System.out.println("==============");

        // 创建了接口的匿名实现类的匿名对象
        computer.transferData(new USB() {
            @Override
            public void start() {
                System.out.println("The MP3 start work!");
            }

            @Override
            public void stop() {
                System.out.println("The MP3 stop work!");
            }
        });

    }

}

class Computer{
    public void transferData(USB usb){
        usb.start();

        System.out.println("Start transfer data！");

        usb.stop();

    }
}

interface USB{
    // 定义长宽，速度等信息

    void start();

    void stop();

}

class Flash implements USB{


    @Override
    public void start() {
        System.out.println("The USB is start work!");

    }

    @Override
    public void stop() {
        System.out.println("The USB is stop work!");

    }
}